package com.lzh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzh.common.bean.PageBean;
import com.lzh.mapper.ProductMapper;
import com.lzh.query.ProductQuery;
import com.lzh.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;


    @Override
    public PageBean query(ProductQuery productQuery) {
        PageHelper.startPage(productQuery.getPage(), productQuery.getPageSize());
        List<Map> query = productMapper.query(productQuery);
        PageInfo<Map> pageInfo = new PageInfo<>(query);
        return new PageBean(productQuery.getPage(), productQuery.getPageSize(),pageInfo.getTotal(),query);
    }

    @Override
    public List<Map> queryByPid(Integer pid) {
        List<Map> maps = productMapper.queryByPid(pid);

        return maps;
    }
}
